﻿


$.MGJ.OriginsTemplet = [];

var OriginsTemplet = $.MGJ.OriginsTemplet;


(function () {
    var _this = $.MGJ.OriginsTemplet;
    $.extend($.MGJ.OriginsTemplet, {
        //保存
        Ajax_SaveOriginsTemplet: function () {
            var bootstrapValidator = $("#Template_form").data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                $.L.ajaxHandle({
                    url: ACTION_URL("SaveTemplet", "OriginsTemplet"),
                    data: $("#Template_form").serialize(),
                    success: function (result) {
                        if (result > 0) {
                            NodeConfig.Ajax_GetTempletNodeList(result);
                            TempletList.Ajax_GetOriginsTempletPageList(TempletList.conditionModel.pageIndex);
                    
                            //$.L.msgSuccess("操作成功");
                            $("#TempletId").val(result);
                            $("#FlowID").val(result);
                            $("#config_").attr("data-toggle", "tab").click()
                        }
                    }
                });
                $("#config_").click()
            }
            else {
                $.L.msgError("请检查数据格式！");
            };
        },

        //获取行业菜单目录
        Ajax_GetTableTree: function (id) {
            $.L.ajaxHandle({
                url: ACTION_URL("getClassifyTree", "Product") + "?EID=" + id,
                success: function (data) {
                    //console.log(data)
                    gridTree = new TableTree4J("gridTree", "../");
                    gridTree.tableDesc = "<table border=\"1\" class=\"GridView table table-bordered \" width=\"100%\" id=\"table1\" cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse: collapse\"  bordercolordark=\"#C0C0C0\" bordercolorlight=\"#C0C0C0\" bordercolorlight=\"#C0C0C0\" >";
                    var headerDataList = new Array("菜单名");
                    var widthList = new Array("20%", "30%", "10%", "30%");
                    gridTree.setHeader(headerDataList, -1, widthList, true, "tittle-bg");
                    //设置列样式
                    gridTree.gridHeaderColStyleArray = new Array("", "", "", "centerClo1");
                    gridTree.gridDataCloStyleArray = new Array("", "", "", "centerClo2");
                    $("#sel_parent_meun").html("<option value='0'>无</option>");
                    $(data).each(function (i, d) {
                        var MenuName = "";
                        if (d.PID != 0) {
                            //MenuName += "<span onclick='javascript:$(\"#CategoryId\").val(" + d.ID + ")'>" + d.Name + "</span>";
                            MenuName += "<span menuname=\"" + d.ID + "\" >" + d.Name + "</span>";
                        }
                        else {
                            MenuName += "<span>" + d.Name + "</span>";
                        }

                        var dataList = new Array(MenuName);

                        //1：对象，2：编号，3：父节点 默认为0，null，5:顺序
                        gridTree.addGirdNode(dataList, d.ID, d.PID == 0 ? -1 : d.PID, null, d.Sequence);
                        //$("#sel_parent_meun").append("<option value='" + d.ID + "'>" + d.MenuName + "</option>");
                    });
                    gridTree.printTableTreeToElement("gridTreeDiv");
                }
            })
        },
    })

})(jQuery);





(function () {

    var _this = $.MGJ.OriginsTemplet;
    $.extend($.MGJ.OriginsTemplet, {
        //溯源节点配置
        CutButtonInfo: function (type) {
            var flowId = $("#TempletId").val();
            if (flowId !=0) {
                NodeConfig.Ajax_GetTempletNodeList(flowId);
                $("#config_").attr("data-toggle", "tab")
                return;
            }
        },
        //溯源节点目录
        CutButtonMenu: function () {
            $("button[data-btnname='button_save']").text("下一步");
            $("button[data-btnname='button_LastStep']").attr("class", "btn btn-primary hidden");
        }
    });
})(jQuery);





$(document).ready(function () {

    OriginsTemplet.Ajax_GetTableTree(1);
  
    var templetId=$("#TempletId").val()
    if (templetId != "0") {
        $("#FlowID").val(templetId);
        $("#config_").click()
    } 

});




var GRIDTREESTYLEID
$(document).on("click", ".GRIDTREESTYLE", function () {
    $(".GRIDTREESTYLE").css("background", "#FFFFFF")
    $(this).css("background", "rgb(207, 223, 243)")
    GRIDTREESTYLEID = $(this).parent().attr("id")

    if ($(this).children("span").attr("menuname") != undefined) {
        $("input[name='ClassifyId']").val($(this).children("span").attr("menuname"))
    }

    if ($("input[name='ClassifyId']").val() != "") {

        $("#ClassifyName").val($(this).children("span").html())
        $("#menu_right").show()

    }
});


//未知函数，待删除
function toggle_content(id) {

    if (id === 'menu_') {
        $('#myTabContent').children().remove();
        var Template_form = document.querySelector('#mytemplate').content.querySelector('#Template_form');
        var clone = document.importNode(Template_form, true);
        $('#myTabContent').append(clone);
        $.MGJ.OriginsTemplete.Ajax_GetTableTree(1);

    }
    else {
        $('#myTabContent').children().remove();
        var config = document.querySelector('#mytemplate').content.querySelector('#config');
        var clone = document.importNode(config, true);
        $('#myTabContent').append(clone);

    }
}




var templetTest = [];
$.extend(templetTest, {

    BindTableTree: function () {
        //console.log("加载目录");
    },

    SelectClassify: function () {
        //Console.log("选择目录");
    },

    SaveTemplet: function () {
        //Console.log("保存模板");
    }

});


$(document).ready(function () {

    if ($("#TempletId").val() != "0") $("#config_").click()

});
